<?php
function html_log($msg, $stop, $start){
?>
  <!-- <?= $msg ?> :: <?= $stop - $start ?> seconds elapsed -->
  
  
<?php
}

$global_start = microtime(true);

$fullname = $_SESSION['first'].' '.$_SESSION['last'];
$imei = $_SESSION['imei'];

$tmp_start = microtime(true);
$flickrurl = "http://www.flickr.com/photos/37983522@N02/";

$images = array();

$db = new PDO('sqlite:'.$DATABASE);
$sqlquery = "SELECT emailassociations.email, emailassociations.activated FROM emailassociations,user WHERE userid=user.ROWID AND user.username = :username";
$stmt = $db->prepare($sqlquery);
$stmt->bindValue(':username', $username, PDO::PARAM_STR);
$stmt->execute();

$emails = $stmt->fetchAll();

?>


<hr class="space" />    
<div class="span-4">
<?php
	$tmp_start = microtime(true);
	require("plant_list_user_page.php");
//	html_log('plant_list_user', microtime(true), $tmp_start);
?>
</div>
<div class="box span-11">
    <div id="current_emails">
	    	<div>
	    		<h3 style="font-weight: bold">Email Associations &#151; Currently Active Associations</h3>
	    		<?php 
	    		if($no_error && isset($error_message)){
	    			?>
	    			<div class="span-10 success">
	    			SUCESS: <?php echo $error_message ?>	
	    			</div>    		
	    		<?php	
    			}
	    		else if(!$no_error){
	    			?>
	    			<div class="span-10 error">
						ERROR: <?php echo $error_message ?>
					</div>
				<?php	
				}				
				?>
	    		<table class="associated_emails_table" border="2">
	    			<tr>
	    			<th colspan="2" class="email_first"><a href="#" onclick="addNotification(this);"><img src="images/new.gif" title="New Associations"/></a>           #</th>
	    			<th class="email_first">Associated Email</th>
	    			<th>Activated</th>
	    			</tr>	    		
	    			<?php
	    			$counter =1;
	    			if($emails){
	    			foreach ($emails as $email){
	    				$activated = $email['activated'] ?'Yes':'No';	    				
	    				echo "<tr><td><a href=\"#\" onclick=\"delConfirm('" .$email['email'] ."');\"><img src=\"images/trash2.gif\" title=\"Delete\"/></a></td><td class=\"email_first\">$counter</td><td class=\"email_first\">" .$email['email'] ."</td><td>$activated</td></tr>";
	    				$counter++;
	    			}
    				}else{
    					echo "<tr><td></td><td></td></tr>";
    				}
	    			
	    			?>
	    			
	    			
	    		</table>

	    	</div>
	    	
	</div>
	    <!-- <div id="add_link"><a href="#" onclick="addNotification();">Add New Notification</a></div> -->
		<div id="notifications_settings" style="display:none">
			<div id="new_notification">
				<h3 style="font-weight: bold"><a href="#" onclick="removeNotification();"><img src="images/x.gif" title="Cancel"/></a> Emails &#151; Add new Association</h3>

					
				<form action="user_emails.php" method="POST">
					<input name="add_email" value="true" type="hidden" />
					<!--<input name="username" type="hidden" value="<?php echo $username?>" />	-->				
					<ul>
					<li>
						<label for="new_email">New email to associate?</label>
						<input name="new_email" id="new_email" type="text">
					</li>			
					</ul>					
					<input type="submit" value="Save">
				</form>
			</div>
			
		</div>  	    
	</div>
</div>	
<?php 
//html_log('finished', microtime(true), $global_start);
?>
